/*
 * SoftwareSAR - 1.0
 */
package br.com.cpqd.ssar.utilitarias;

/**
 * Classe que Representa um Triângulo no Espaço 3D
 * @author Rafael Buck
 * @version 1.1
 */
public class Triangulo {

    /**
     * Vértices do Triângulo
     */
    private Vertice[] vertice;
    /**
     * Vetor Normal ao Triângulo
     */
    private float[] normal;

    /**
     * Método Construtor
     */
    public Triangulo() {
        vertice = new Vertice[3];
        vertice[0] = new Vertice();
        vertice[1] = new Vertice();
        vertice[2] = new Vertice();
        normal = new float[3];
    }

    /**
     * Método Construtor Sobrecarregado
     * @param vertice Vertice
     * @param normal float[]
     */
    public Triangulo(Vertice[] vertice, float[] normal) {
        this.vertice = vertice;
        this.normal = normal;
        if (vertice.length == 3) {
            this.vertice = vertice;
            this.normal = normal;
        } else {
            vertice = new Vertice[3];
            normal = new float[3];
            System.out.println("Erro - Classe Triangle: Atribuição de mais de 3 pontos a um triângulo");
        }
    }

    /**
     * Seta as Propriedades do Triangule com as de outro
     * @param triangulo Triangulo
     */
    public void setup(Triangulo triangulo) {
        vertice[0].setCoordenada(0, triangulo.getVertice(0).getCoordenada(0));
        vertice[0].setCoordenada(1, triangulo.getVertice(0).getCoordenada(1));
        vertice[0].setCoordenada(2, triangulo.getVertice(0).getCoordenada(2));

        vertice[1].setCoordenada(0, triangulo.getVertice(1).getCoordenada(0));
        vertice[1].setCoordenada(1, triangulo.getVertice(1).getCoordenada(1));
        vertice[1].setCoordenada(2, triangulo.getVertice(1).getCoordenada(2));

        vertice[2].setCoordenada(0, triangulo.getVertice(2).getCoordenada(0));
        vertice[2].setCoordenada(1, triangulo.getVertice(2).getCoordenada(1));
        vertice[2].setCoordenada(2, triangulo.getVertice(2).getCoordenada(2));

        normal[0] = triangulo.getNormal()[0];
        normal[1] = triangulo.getNormal()[1];
        normal[2] = triangulo.getNormal()[2];
    }

    /**
     * Get the value of vertice
     * @return the value of coordenada
     */
    public Vertice[] getVertice() {
        return vertice;
    }

    /**
     * Set the value of vertice
     * @param vertice new value of vertice
     */
    public void setVertice(Vertice[] vertice) {
        if (vertice.length == 3) {
            this.vertice = vertice;
        } else {
            System.out.println("Erro - Classe Triangle: Atribuição de mais de 3 pontos a um triângulo");
        }
    }

    /**
     * Get the value of vertice at specified index
     * @param index int
     * @return the value of vertice at specified index
     */
    public Vertice getVertice(int index) {
        if ((index >= 0) & (index <= 2)) {
            return this.vertice[index];
        } else {
            System.out.println("Erro - Classe Triangle: Valor de índice fora dos limites");
            return null;
        }
    }

    /**
     * Set the value of vertice at specified index.
     * @param index int
     * @param newVertice new value of vertice at specified index
     */
    public void setVertice(int index, Vertice newVertice) {
        if ((index >= 0) & (index <= 2)) {
            this.vertice[index] = newVertice;
        } else {
            System.out.println("Erro - Classe Triangle: Valor de índice fora dos limites");
        }
    }

    /**
     * Get the value of normal
     * @return the value of normal
     */
    public float[] getNormal() {
        return normal;
    }

    /**
     * Set the value of normal
     * @param normal new value of normal
     */
    public void setNormal(float[] normal) {
        this.normal = normal;
    }

    /**
     * Get the value of normal at specified index
     * @param index
     * @return the value of normal at specified index
     */
    public float getNormal(int index) {
        return this.normal[index];
    }

    /**
     * Set the value of normal at specified index.
     * @param index
     * @param newNormal new value of normal at specified index
     */
    public void setNormal(int index, float newNormal) {
        this.normal[index] = newNormal;
    }
}
